Connecting via Python
The following example shows how to connect to the MariaDB server via python.
Install pyodbc
pip install pyodbc
Connect to your server
import pyodbc
class MssqlConnection(object):
def __init__(self):
self.SERVER = 'connect server'
self.PORT = 4098 # your port
self.UID = 'login user'
self.PASSWORD = 'user password'
self.DATABASE = 'master'
def connect_mssql(self):
conn = pyodbc.connect(
'DRIVER={ODBC Driver 17 for SQL Server};'
'SERVER=%s,%s;'
'DATABASE=%s;'
'UID=%s;'
'PWD=%s' % (self.SERVER, self.PORT, self.DATABASE, self.UID, self.PASSWORD),
autocommit=True)
return conn
def operate_database(self):
# example select login user
connect = self.connect_mssql()
cursor = connect.cursor()
cursor.execute("exec sp_helplogins;")
user_list = [i[0] for i in cursor.fetchall()]
print(user_list)
connect.close()
if __name__ == '__main__':
MssqlConnection().operate_database()